package com.ayoka.ui.course.course_package;

import android.os.Bundle;
import android.view.View;

import com.ayoka.R;
import com.ayoka.base.BaseFragment;
import com.ayoka.base.BasePresenter;
import com.ayoka.bean.CoursePackageBean;
import com.ayoka.databinding.FragmentCoursePackageBinding;
import com.ayoka.mvp.CoursePackageMVP.CoursePackagePresenter;
import com.jincp.image.load.ImageLoaderProxy;

/**
 * 首页的Fragment
 * <p>
 * Created by admin on 2017/3/22.
 */

public class CoursePackageFragment extends BaseFragment<FragmentCoursePackageBinding, BasePresenter> {

    public static CoursePackageFragment newInstance(CoursePackageBean coursePackageBean) {
        CoursePackageFragment homePageCourseFragment = new CoursePackageFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("CoursePackageBean", coursePackageBean);
        homePageCourseFragment.setArguments(bundle);
        return homePageCourseFragment;
    }

    private CoursePackageBean coursePackageBean;

    @Override
    protected void configBundleArguments() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            coursePackageBean = (CoursePackageBean) bundle.getSerializable("CoursePackageBean");
        }
    }

    @Override
    public int getContentLayout() {
        return R.layout.fragment_course_package;
    }

    @Override
    protected void initViews(View view) {
        mDataBinding.layoutCoursePackageContainer.setOnClickListener(this);
    }

    @Override
    public void initData() {
        configCoursePackageDetailData();
    }

    @Override
    protected CoursePackagePresenter getPresenter() {
        return null;
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        if (view == mDataBinding.layoutCoursePackageContainer) {
            CoursePackageDetailActivity.start(getActivity(), coursePackageBean.PackageName, coursePackageBean.ID);
        }
    }

    private void configCoursePackageDetailData() {
        ImageLoaderProxy.getInstance().displayImage(coursePackageBean.ImgUrl, mDataBinding.ivPicture);
        mDataBinding.tvCoursePackageName.setText(coursePackageBean.PackageName);
        mDataBinding.tvCoursePackageDescription.setText(coursePackageBean.SubTitle);
        mDataBinding.tvCoursePersonNumber.setText(String.valueOf(coursePackageBean.getParticipationTimes()));
    }
}
